package com.atguigu.spzx.utils;

import com.atguigu.spzx.model.entity.system.SysUser;

/**
 * ClassName: AuthContextUtil
 * Package: com.atguigu.spzx.utils
 * Description:
 *      线程本地变量的工具类
 * @Author 刘强
 * @Create 2024/7/1 10:20
 * @Version 1.0
 */
public class AuthContextUtil {
    private static final ThreadLocal<SysUser> THREAD_LOCAL = new ThreadLocal<>();

    /**
     *  向线程本地变量中添加用户信息
     * @param sysUser
     */
    public static void set(SysUser sysUser){
        THREAD_LOCAL.set(sysUser);
    }

    /**
     * 从线程本地变量中获取用户信息
     * @return
     */
    public static SysUser get(){
        return THREAD_LOCAL.get();
    }

    /**
     * 删除线程本地变量
     */
    public static void remove(){
        THREAD_LOCAL.remove();
    }
}
